package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.ServeType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IServeTypeService;
import com.ruoyi.system.service.impl.ServeTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 服务类型表 前端控制器
 * </p>
 *
 * @author wahaha
 * @since 2024-10-17
 */
@RestController
@RequestMapping("/system/serveType")
public class ServeTypeController extends BaseController {
    @Autowired
    private IServeTypeService serveTypeService;

    /**
     * 查询服务类型列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServeType serveType) {
        startPage();
        List<ServeType> list = serveTypeService.selectServeTypeList(serveType);
        return getDataTable(list);
    }

    /**
     * 导出服务类型列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "服务类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServeType serveType) {
        List<ServeType> list = serveTypeService.selectServeTypeList(serveType);
        ExcelUtil<ServeType> util = new ExcelUtil<ServeType>(ServeType.class);
        util.exportExcel(response, list, "服务类型数据");
    }

    /**
     * 获取服务类型详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(serveTypeService.selectServeTypeById(id));
    }

    /**
     * 新增服务类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "服务类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServeType serveType) {
        return toAjax(serveTypeService.insertServeType(serveType));
    }

    /**
     * 修改服务类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "服务类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServeType serveType) {
        return toAjax(serveTypeService.updateServeType(serveType));
    }

    /**
     * 删除服务类型
     */
//    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "服务类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(serveTypeService.deleteServeTypeByIds(ids));
    }
}



